# -*- coding: utf-8 -*-
"""
Created on Tue Apr 16 13:23:21 2024
数据框中的loc属性则主要是基于列标签进行索引，
即对列值进行筛选实现行定位，再通过指定列，从而实现数据切片操作
@author: 29865
"""
import pandas as pd
import numpy as np
data = {'a': [2, 2, np.nan, 5, 6],
        'b': ['kl', 'kl', 'kl', np.nan, 'kl'],
        'c': [4, 6, 5, np.nan, 6],
        'd': [7, 9, np.nan, 9, 8]}
df = pd.DataFrame(data)

# 使用一个固定的值填充所有 NaN
df_filled = df.fillna(0)

c8 = df_filled.loc[df_filled['b'] == 'kl', :]
c9 = df_filled.loc[df_filled['b'] == 'kl', :].head(3)
c10 = df_filled.loc[df_filled['b'] == 'kl', ['a', 'c']].head(3)
c11 = df_filled.loc[df_filled['b'] == 'kl', ['a', 'c']]
